import {ADD_COMMENT, DELETE_COMMENT, RECEIVE_COMMENTS} from './action-types'

//同步
export const addComment = (comment) => ({type: ADD_COMMENT, data: comment});
export const deleteComment = (index) => ({type: DELETE_COMMENT, data: index});

const receiveComment = (comments) => ({type: RECEIVE_COMMENTS, data: comments});
//异步
export const getComment = () => {
    return dispatch => {
        //异步代码
        setTimeout(() => {
            const comments = [
                {username: 'Tom', content: 'React挺好的！'},
                {username: 'Jack', content: 'React好难啊！'}
            ];
            dispatch(receiveComment(comments));
        }, 1000);
    }
};